package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @author げっしょく
 * @date 2021/9/12
 */
public class MybatisConfig {

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sql = new SqlSessionFactoryBean();

        sql.setTypeAliasesPackage("com.itheima.domain");

        sql.setDataSource(dataSource);

        return sql;
    }

    @Bean
    //扫描dao层接口所在的包，根据接口和对应的SQL产生接口的实现类对象
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.itheima.dao");
        return msc;
    }
}
